package com.caiden_micheal.user.utils;

import com.caiden_micheal.base.utils.BaseContext;
import com.caiden_micheal.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class PermissionCheckUtil {
    @Autowired
    private static UserService userService;

    @Resource
    public void setUserService(UserService userService) {
        PermissionCheckUtil.userService = userService;
    }

    public static Boolean checkPermission(String authorityName) {
        List<String> authNameList = userService.findUserAuthorityNameListByUserId(Long.valueOf(BaseContext.getInfo().get("userId").toString()), false);
        return authNameList.contains(authorityName);
    }
}
